from flask import request
from SQLOperation.PatientSQLOperation import PatientSQLOperation
from SQLConfig import app
from updateProjectFile import changeProjectFile


@app.route('/updatePatientInformation', methods=['Get', 'POST'])
def updatePatientInformation():  # put application's code here
    """
    修改患者信息
    """

    # 判断是否存在此用户
    patientId = request.json.get("patientId")
    user = PatientSQLOperation.searchById(patientId)
    if user is None:
        return "patient not exist"

    # 修改姓名
    name = request.json.get("name")
    if name is not None:
        PatientSQLOperation.updateById(patientId=patientId, name=name)
        changeProjectFile(patientId, "patientInformation", "update", "name", name)

    # 修改性别
    gender = request.json.get("gender")
    if gender is not None:
        PatientSQLOperation.updateById(patientId=patientId, gender=gender)
        changeProjectFile(patientId, "patientInformation", "update", "gender", gender)

    # 修改年龄
    age = request.json.get("age")
    if age is not None:
        PatientSQLOperation.updateById(patientId=patientId, age=age)
        changeProjectFile(patientId, "patientInformation", "update", "age", age)

    # 修改时间
    time = request.json.get("time")
    if time is not None:
        PatientSQLOperation.updateById(patientId=patientId, time=time)
        changeProjectFile(patientId, "patientInformation", "update", "time", time)

    # 修改手机号
    phone = request.json.get("phone")
    if phone is not None:
        PatientSQLOperation.updateById(patientId=patientId, phone=phone)
        changeProjectFile(patientId, "patientInformation", "update", "phone", phone)

    return "OK"
